package training.collections;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MapDemo {

	
	class Person{
		private String name;
		
		Person(String name){
			this.name = name;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}
		
		@Override
		public String toString() {
			return "*** Name is " + name;
		}
		
		
	}
	
	public void mapExample(){
		
		Map<String, Person> personsMap = new HashMap<String, Person>();
		
		personsMap.put("Hari", new Person("Hari"));
		personsMap.put("Ambika", new Person("Ambika"));
		personsMap.put("Nisha", new Person("Nisha"));
		
		
		System.out.println("Person object name with key as Hari is " + personsMap.get("Hari"));
		Set<String> keys = personsMap.keySet();
		
		
		//keys.iterator(); this is one way of accessing map data
		
		for (String key : keys) {
			
			System.out.println("Key is :" + key + "  Value is : " + personsMap.get(key));
		}
		
		
		
		
	}
	
	public static void main(String[] args) {
		MapDemo demo = new MapDemo();
		//demo.map
		demo.mapExample();

	}

}
